import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Represent a LED if is on or if is off.
 * 
 * @author Christian Pérez Zavalija
 * @version 25-Jun-2013
 */
public class LED extends Device
{
    private GreenfootImage []imgLed;
    
    /**
     *  Load the images in an array and displays the LED-off and called to the constructor of the super class.
     */
    public LED()
    {
        super(2,12,44);
        /*for(int i=0;i<2;i++)
            pins[i].charge=0;*/
        imgLed=new GreenfootImage[2];
        imgLed[0]= new GreenfootImage("LED-off.png");
        imgLed[1]= new GreenfootImage("LED-on.png");
        setImage(imgLed[0]);
    }
    
    /**
     * The image is scale in 100%
     */
    public void scale()
    {
        imgLed[0].scale(imgLed[0].getWidth(),imgLed[0].getHeight());
    }
    
    /**
     * if you touch one of the pins with the dump, the pins are removed.
     */
    public void eliminate()
    {
        removeTouching(Pin.class);
    }
    
    /**
     * Changes the image to LED-off.
     */
    public void OFF()
    {
        setImage(imgLed[0]);
    }
    
    /**
     * Changes the image to LED-on.
     */
    public void ON()
    {
        setImage(imgLed[1]);
    }
    
    /**
     * Changes to the image if the pin they are connected to their respective loads.
     */
    public void act() 
    {
        super.act();
        if(pins[0].charge==0&&pins[1].charge==1)
            this.ON();
        else
            this.OFF();
    }    
}
